package com.qeeyou.apps.android.craftsman.fragment;


import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import com.qeeyou.apps.android.craftsman.R;
import com.qeeyou.apps.android.craftsman.adapter.MessageAdapter;
import com.qeeyou.apps.android.craftsman.po.MessageInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by xuchengxiong on 2017/12/14.
 */

public class MessageFragment extends BaseFragment {

    private ListView lstvMessage;
    private MessageAdapter mAdapter;
    private List<MessageInfo> messageList;

    public MessageFragment() {
       super(R.layout.fragment_message);
    }

    @Override
    protected void doOnCreate(Bundle savedInstanceState) {

        setView();
        setEvent();
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    private void setView() {
        lstvMessage = (ListView) this.findViewById(R.id.lstvMessage4Message);
    }

    private void setEvent() {
        testData();
        mAdapter = new MessageAdapter(MessageFragment.this.getActivity(), messageList);
        lstvMessage.setAdapter(mAdapter);
        lstvMessage.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Toast.makeText(MessageFragment.this.getActivity(), "消息Item点击事件", Toast.LENGTH_SHORT).show();
            }
        });

    }

    private void testData() {
        if(messageList == null) {
            messageList = new ArrayList<>();
        }
        messageList.clear();

        MessageInfo messageInfo0 = new MessageInfo();
        messageInfo0.setAvatarUrl(null);
        messageInfo0.setChatId("0");
        messageInfo0.setGender("0");
        messageInfo0.setId("0");
        messageInfo0.setName("上官云轻");
        messageInfo0.setMessage("你好啊, 你做橱窗多久了? ");
        messageInfo0.setRecentTime("下午14:20");
        messageList.add(messageInfo0);

        MessageInfo messageInfo1 = new MessageInfo();
        messageInfo1.setAvatarUrl(null);
        messageInfo1.setChatId("1");
        messageInfo1.setGender("1");
        messageInfo1.setId("1");
        messageInfo1.setName("上官云清");
        messageInfo1.setMessage("你昨晚的提议非常好, 我觉得你的意见提的很恰到好处... ");
        messageInfo1.setRecentTime("上午10:40");
        messageList.add(messageInfo1);

        MessageInfo messageInfo2 = new MessageInfo();
        messageInfo2.setAvatarUrl(null);
        messageInfo2.setChatId("2");
        messageInfo2.setGender("0");
        messageInfo2.setId("2");
        messageInfo2.setName("张国华");
        messageInfo2.setMessage("你好, 你现在有时间吗? ");
        messageInfo2.setRecentTime("昨天");
        messageList.add(messageInfo2);

        MessageInfo messageInfo3 = new MessageInfo();
        messageInfo3.setAvatarUrl(null);
        messageInfo3.setChatId("3");
        messageInfo3.setGender("1");
        messageInfo3.setId("3");
        messageInfo3.setName("9()牛牛机智豆");
        messageInfo3.setMessage("你昨晚的提议非常好, 我觉得你的意见提的很恰到好处... ");
        messageInfo3.setRecentTime("周三");
        messageList.add(messageInfo3);

        MessageInfo messageInfo4 = new MessageInfo();
        messageInfo4.setAvatarUrl(null);
        messageInfo4.setChatId("4");
        messageInfo4.setGender("1");
        messageInfo4.setId("4");
        messageInfo4.setName("芥末ing");
        messageInfo4.setMessage("你的橱柜安装得非常棒, 谢谢你啊 ");
        messageInfo4.setRecentTime("周二");
        messageList.add(messageInfo4);

        MessageInfo messageInfo5 = new MessageInfo();
        messageInfo5.setAvatarUrl(null);
        messageInfo5.setChatId("5");
        messageInfo5.setGender("0");
        messageInfo5.setId("5");
        messageInfo5.setName("上官云轻");
        messageInfo5.setMessage("你好啊, 你做橱窗多久了? ");
        messageInfo5.setRecentTime("下午14:20");
        messageList.add(messageInfo5);

        for(int i = 0; i < 20; i ++) {
            MessageInfo messageInfo = new MessageInfo();
            messageInfo.setAvatarUrl(null);
            messageInfo.setChatId(6 + i + "");
            messageInfo.setGender("0");
            messageInfo.setId(6 + i + "");
            messageInfo.setName("上官云轻");
            messageInfo.setMessage("你好啊, 你做橱窗多久了? ");
            messageInfo.setRecentTime("下午14:20");
            messageList.add(messageInfo);
        }
    }
}
